import 'package:flutter/material.dart';
import '../../model/post.dart';
import 'cource_detail.dart';

class CourseWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: posts.length,
        itemBuilder: _listItemBuilder
      );
  }

  Widget _listItemBuilder(BuildContext context, int index) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.all(10.0),
      child: Stack(
        children: [
          Column(
            children: <Widget>[
              AspectRatio(
                aspectRatio: 16/9,
                child: Image(
                  image: AssetImage(posts[index].imageUrl),
                  fit: BoxFit.cover,
                ),
              ),
              SizedBox(height: 16.0,),
              Text(
                posts[index].title,
                style: TextStyle(
                  fontSize: 24.0,
                  fontWeight: FontWeight.w500,
                  color: Colors.green,
                ),
              ),
              SizedBox(height: 8.0,),
              Text(
                posts[index].author,
                style: TextStyle(
                  fontSize: 16.0,
                  color: Colors.green,
                ),
              ),
              SizedBox(height: 8.0,),
            ],
          ),
          Positioned.fill(
            child: Material(
              color: Colors.transparent,
              child: InkWell(
                splashColor: Colors.white,
                highlightColor: Colors.white.withOpacity(0.1),
                onTap: () {
                  // debugPrint('Tap');
                  Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => CourseDetailWidget(post: posts[index],)
                    ),
                  );
                },
              ),
            ),
          ),
        ],
      )
    ); 
  }
}